#!/usr/bin/python

##################
# chanpanel.py
#
# Copyright David Baddeley, 2009
# d.baddeley@auckland.ac.nz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##################

#!/usr/bin/env python
# generated by wxGlade 0.3.3 on Thu Jun 17 09:28:57 2004

import wx
import previewaquisator
import chanedit

class ChannelPan(wx.Panel):
    def __init__(self, chaninfo, parent,*args, **kwds):
        # begin wxGlade: ChannelPan.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self,parent,-1, *args, **kwds)

        self.chaninfo = chaninfo

        self.lChans = wx.ListBox(self, -1,size=(180,60),  choices=[])
        self.bAdd = wx.Button(self, -1, "Add")
        self.bEdit = wx.Button(self, -1, "Edit")
        self.bDelete = wx.Button(self, -1, "Delete")

        wx.EVT_BUTTON(self, self.bAdd.GetId(), self.onAdd)
        wx.EVT_BUTTON(self, self.bEdit.GetId(), self.onEdit)
        wx.EVT_BUTTON(self, self.bDelete.GetId(), self.onDelete)

        self.UpdateList()

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: ChannelPan.__set_properties
        self.lChans.SetSelection(0)
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: ChannelPan.__do_layout
        sizer_6 = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Channels"), wx.HORIZONTAL)
        sizer_7 = wx.BoxSizer(wx.VERTICAL)
        sizer_6.Add(self.lChans, 1, wx.ALL|wx.EXPAND, 5)
        sizer_7.Add(self.bAdd, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5)
        sizer_7.Add(self.bEdit, 0, wx.LEFT, 5)
        sizer_7.Add(self.bDelete, 0, wx.LEFT|wx.BOTTOM, 5)
        sizer_6.Add(sizer_7, 0, 0, 0)
        self.SetAutoLayout(1)
        self.SetSizer(sizer_6)
        sizer_6.Fit(self)
        sizer_6.SetSizeHints(self)
        # end wxGlade

    def UpdateList(self):
        self.chanstrings = []
        for c in range(len(self.chaninfo.names)):
            bef = 0
            s = self.chaninfo.names[c] + '   '
            if (self.chaninfo.cols[c] & previewaquisator.PreviewAquisator.BW):
                s = s + 'BW'
                bef = 1
            if (self.chaninfo.cols[c] & previewaquisator.PreviewAquisator.RED):
                if bef:
                    s = s + '|'
                s = s + 'R'
                bef = 1
            if (self.chaninfo.cols[c] & previewaquisator.PreviewAquisator.GREEN1):
                if bef:
                    s = s + '|'
                s = s + 'G1'
                bef = 1
            if (self.chaninfo.cols[c] & previewaquisator.PreviewAquisator.GREEN2):
                if bef:
                    s = s + '|'
                s = s + 'G2'
                bef = 1
            if (self.chaninfo.cols[c] & previewaquisator.PreviewAquisator.BLUE):
                if bef:
                    s = s + '|'
                s = s + 'B'
                bef = 1
            
            h = self.chaninfo.hw[c]
            s = s + '   ' + '%d%d%d%d%d%d%d%d' % (h&1, h&2, h&4, h&8, h&16, h&32, h&64, h&128)
            
            self.chanstrings.append(s)
        self.lChans.Set(self.chanstrings)

        if len(self.chanstrings) > 0:
            self.bEdit.Enable(True)
            self.bDelete.Enable(True)
        else:
            self.bEdit.Disable()
            self.bDelete.Disable()

    def onAdd(self, event):
        ce = chanedit.ChanEditDialog('',0,0, None, -1, '')
        if (ce.ShowModal()):
            self.chaninfo.names.append(ce.cname)
            self.chaninfo.cols.append(ce.cols)
            self.chaninfo.hw.append(ce.hw)
            self.chaninfo.itimes.append(100)
            self.UpdateList()
        self.lChans.SetSelection(len(self.chaninfo.names)-1)

    def onEdit(self, event):
        ind = self.lChans.GetSelection()
        ce = chanedit.ChanEditDialog(self.chaninfo.names[ind],self.chaninfo.cols[ind],self.chaninfo.hw[ind], None, -1, '')
        if (ce.ShowModal()):
            self.chaninfo.names[ind] = ce.cname
            self.chaninfo.cols[ind] = ce.cols
            self.chaninfo.hw[ind] = ce.hw
            self.UpdateList()
        self.lChans.SetSelection(ind)

    def onDelete(self, event):
        ind = self.lChans.GetSelection()
        self.chaninfo.names.pop(ind)
        self.chaninfo.cols.pop(ind)
        self.chaninfo.hw.pop(ind)
        self.chaninfo.itimes.pop(ind)
        self.UpdateList()
        self.lChans.SetSelection(0)



# end of class ChannelPan


